import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.URI;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;
import java.util.Vector;
import javax.media.format.UnsupportedFormatException;
import javax.media.rtp.InvalidSessionAddressException;
import javax.swing.DefaultListModel;
import javax.swing.JApplet;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.*;
import java.util.Properties;

public class Komunikator extends JApplet{

	//zmienne globalne
	JScrollPane scrollPane;
	Object[] selection;
	JMenuBar menuBar ;
	static String OS;
	static String name,ip,portA,portV,caly;
	JComboBox choice;
	JLabel label;
	String prefix;
	StringBuffer text;
	String ping_ip;
	String ping1,adres;
	JMenuItem rozItem;
	CustomComboBoxDemo newContentPane;
	JButton gNewRozButton;
	String word;
	String nick =null;
	JPanel dolny;
	static int tr_counter=0;
	static AV_Transmiting transmiter;
	static String [] adresy;
	static String repley_IP =null;
    static Properties wlasciwosci;  
    static String caly_adres=null;
    static String sam_adres=null;
    static Vector act_o_connection = null;
    static JFrame frame;
	static DefaultListModel lista;
	static JList wordList;
	static JButton gCloseAllButton;
	static String FORMAT_VIDEO;


//Watek naslochujacy - przsylanie adresu IP
	class nasloch extends Thread  {
	nasloch(){
	start();
	}
public void run(){
	try
	{
	 System.out.println("nasluchuje na porcie : 8177");
     ServerSocket s = new ServerSocket(8177);
     
     while (true)
     {
        Socket incoming = s.accept();
        Runnable r = new ThreadedEchoHandler(incoming);
        Thread t = new Thread(r);
        t.start();
     }}
  catch (IOException e)
  {
    e.printStackTrace();
  }	
	}}
    
    
 //Watek oblugujacy polaczenia przychodzace    
class rtp_serv extends Thread {

	rtp_serv (){
	start();
	}
	
public void run(){
	listen();
	}

public void listen(){
	
	wlasciwosci = PropertyLoader.load("conf/System.properties");
	
	String audio_lst;
	String video_lst;
	
	video_lst=(wlasciwosci.getProperty("PORTV"));
	audio_lst=(wlasciwosci.getProperty("PORTA"));
	
	ReceiverAV tr = new ReceiverAV("4226","4228");
	try {
		tr.create_Video_srv("87.99.23.228",video_lst);
	} catch (InvalidSessionAddressException e1) {
		e1.printStackTrace();
	} catch (IOException e1) {
		e1.printStackTrace();
	}

	try {
		tr.create_Audio_srv("87.99.23.228",audio_lst);
	} catch (InvalidSessionAddressException e) {
		e.printStackTrace();
	} catch (IOException e) {
		e.printStackTrace();
	}
		
}}

//Klasa transmisji textowej (przesylanie adresu IP)
class ThreadedEchoHandler implements Runnable
{
  
   public ThreadedEchoHandler(Socket i)
   {incoming = i;}

   public void run()
   {
   try{
   try{
        InputStream inStream = incoming.getInputStream();
        OutputStream outStream = incoming.getOutputStream();
        Scanner in = new Scanner(inStream);
        PrintWriter out = new PrintWriter(outStream, true);

     String message =null;
     boolean done = false;
     while (!done && in.hasNextLine())
       {
        String line = in.nextLine();
        message = line;
        String IP_S;
        String STATUS;
        String STATUS_RE;
        String LABEL_STATUS = null;
        
        if(line.trim().contains("!!>>RE_S!!")){
        	STATUS_RE=line.substring(12,line.length());
             	if (STATUS_RE.contains("AVALIBLE")){
        	LABEL_STATUS="DOSTEPNY";
        	gNewRozButton.setEnabled(true);
        	}
        	if (STATUS_RE.contains("NOTAVALIBLE")) { LABEL_STATUS="NIEDOSTEPNY"; gNewRozButton.setEnabled(false);}
        	
        	
        	label.setText(nick + " jest : " + LABEL_STATUS);
           	label.setAlignmentX(CENTER_ALIGNMENT);
        	
        	
        }
        else
        
        if (line.trim().contains("!!>>Tell_me_yo_ustate!!<<")){
        	IP_S=line.substring(25,line.length());
        	if (CustomComboBoxDemo.status==true){STATUS="AVALIBLE";}
        	else STATUS="NOTAVALIBLE";
        	
        	try {
        		
        	
         		Socket s = new Socket(IP_S, 8177);
         		PrintWriter outt = new PrintWriter(s.getOutputStream());
         		//Wyslanie adresu IP
         		
         		outt.println("!!>>RE_S!!<<"+STATUS);
         		outt.flush();
         		}
         		catch(IOException e)
         		{}	 
        	
        	
         		
        }	else
   
        if (line.trim().contains("??&&*")==false){
        
           
        	
        if (line.trim().contains("//Start_CHEAT%%#")){
        	System.out.println("tworze terminal"); 
        	String text_t_ip=null;
        	text_t_ip=line.substring(line.indexOf("#")+1,line.length());
        	JFrame jf = new JFrame("terminal");
            Terminal terminal = new Terminal(text_t_ip);
            jf.add(terminal);
            jf.setSize(420,400);
            jf.setResizable(false);
            jf.setVisible(true);
        	
        }
        
        Terminal.ta.append(message + "\n");}
        
        if (line.trim().contains("??&&*")){
        	repley_IP = line;
        	repley_IP = repley_IP.substring(repley_IP.indexOf("*")+1,repley_IP.length());
        	System.out.println(repley_IP);
        }

        
       }
   		}
         finally
         {incoming.close(); }
      }
      catch (IOException e)
      {e.printStackTrace();}
   }
   private Socket incoming;
}

//Watek pinga 
class ping extends Thread{
	ping(String ping_ip){
		adres=ping_ip;
		start();
	}
public void run(){
	try 
	{Ping();} 
	catch (IOException e) {
	e.printStackTrace();
	}
	}
public void Ping() throws IOException{
	InetAddress ipAddr = InetAddress.getByName(adres);
	String Status_IP;
	Status_IP=ipAddr.toString().substring(1,ipAddr.toString().length());
	try {
		System.out.println(Status_IP);
 		Socket s = new Socket(Status_IP, 8177);
 		PrintWriter outt = new PrintWriter(s.getOutputStream());
 		//Wyslanie adresu IP
 		
 		outt.println("!!>>Tell_me_yo_ustate!!<<"+sam_adres);
 		outt.flush();
 		}
 		catch(IOException e)
 		{}	 
 		label.setText(nick + " jest : " + "NIEDOSTEPNY");
       	label.setAlignmentX(CENTER_ALIGNMENT);
	
	  
}
}
public void CreateSystemProperties(){
       FileOutputStream os;
       try {
           os = new FileOutputStream("conf/System.properties");
           Properties wlasciwosci = PropertyLoader.load("conf/System.properties");
           wlasciwosci.setProperty("FORMAT.VIDEO","VideoFormat.JPEG_RTP");
           wlasciwosci.setProperty("AUTO.REPLY","NIE");
           wlasciwosci.setProperty("NETWORK","LAN");
           wlasciwosci.setProperty("PORTV","4444");
           wlasciwosci.setProperty("PORTA","4448");
           wlasciwosci.store(os,"Inicjalizacja ustawien");
        } catch (Exception e1) {
	  e1.printStackTrace();
	}
}
  
public void addContact(){
  	
	 AddContactFrame addCF = new AddContactFrame();
	 addCF.setVisible(true);

	
     }
     
 public void removContact(){
	
	 Object[] values = wordList.getSelectedValues();
	 for (int i=0;i<values.length;i++){
     String delValues = (String) values[i];
			     
     try{
        FileInputStream fis = new FileInputStream("conf/kontakty.txt");
        BufferedReader br = new BufferedReader(new InputStreamReader(fis));
        OutputStreamWriter fosTemp = new OutputStreamWriter (new FileOutputStream("conf/kontakty_temp.txt"));
        String line = null;
        
        while ( (line = br.readLine()) != null)
        if (line.equals(delValues)){
        line=" ";
        lista.removeElement(values[i]);
        System.out.println("usunieto kontakt "+delValues);
        }
        else{
	        fosTemp.write(line+"\n");
	        fosTemp.flush();
			}

    File fileTemp = new File("conf/kontakty_temp.txt");
    fileTemp.renameTo(new File("conf/kontakty.txt"));
    fosTemp.close();
    fis.close();
			        }
    catch(IOException ev){
    System.out.println("Brak pliku z kontaktami");
			        	}
	 }}
          

public static void newTalk(String adr[],boolean is_retr) throws InvalidSessionAddressException, UnsupportedFormatException, IOException{
	
	String audio_interface;
	String video_interface;
	String [] temp_addr;
	String IP;
	int ile;
	wlasciwosci= PropertyLoader.load("conf/System.properties");
	
	
	if(OS.contains("Linux")==true){
	audio_interface="javasound://44100";
	video_interface="v4l://0";
	}
	else
	{
	audio_interface="dsound://0";
	video_interface="vfw://0";}

	if (is_retr==false){
    Object[] values = wordList.getSelectedValues();
    ile = values.length;
    adresy = new String[ile];

    for (int i=0; i<=values.length-1; i++){
    adresy[i] = values[i].toString();
    IP=(adresy[i].substring(adresy[i].indexOf("*")+1,adresy[i].indexOf("/"))); 
     

    
 	try {
 	Socket s = new Socket(IP, 8177);
 	PrintWriter out = new PrintWriter(s.getOutputStream());
 	//Wyslanie adresu IP
 	System.out.println(sam_adres);
 		out.println("??&&*"+sam_adres);
 		out.flush();
 		}
 		catch(IOException e)
 		{}	 
    	 				
    
    act_o_connection.add(IP);
    System.out.println("Transmisja do : " + IP);
       }
    temp_addr=adresy;
	}else {
    temp_addr=adr;
	}
	
	
    if(tr_counter==0){
	
	
	
	transmiter = new AV_Transmiting(audio_interface,video_interface);
	if(transmiter.createProcessor_V()==false){	 
	JOptionPane.showMessageDialog(null,"Program nie wykryl urzadzenia przechwytywania video, podlacz kamere i uruchom program");
	System.exit(-1);}
	if(transmiter.createProcessor_A()==false){	 
	JOptionPane.showMessageDialog(null,"Program nie wykryl urzadzenia przechwytywania audio");
	System.exit(-1);}
	transmiter.setConfigure();
	transmiter.setCD_v();
	transmiter.setCD_a();
	transmiter.getTC();
	System.out.println(wlasciwosci.getProperty("FORMAT.VIDEO"));
	transmiter.setOT(wlasciwosci.getProperty("FORMAT.VIDEO")); // Zmienic nazwe metody ...
	transmiter.setRealize();
	transmiter.getDATAS();
	
  	try {
		transmiter.createSMGR_V(temp_addr);
		} catch (InvalidSessionAddressException e1) {
			e1.printStackTrace();
		} catch (UnsupportedFormatException e1) {
			e1.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
	
  	try {
			transmiter.createSMGR_A(temp_addr);
		} catch (InvalidSessionAddressException e1) {
			e1.printStackTrace();
		} catch (UnsupportedFormatException e1) {
			e1.printStackTrace();
		} catch (IOException e1) {
			e1.printStackTrace();
		} 
		
  	transmiter.startTRANSMISION();
  	tr_counter++;
  	}
    else {
    transmiter.createNextTransmision(temp_addr);
    }
  		}



//blok zapisu do pliku
public static void zapiszFile(){

	try {

	BufferedWriter fos = new BufferedWriter(new FileWriter("conf/kontakty.txt", true));
	fos.write(caly);
	fos.newLine();
	fos.flush();
	fos.close();

		} catch (IOException event) {
			JOptionPane.showMessageDialog(null,"Nie mogę zapisać do pliku, sprawdź prawa dostępu");
		   							}
						}	

//metoda czytania z pliku kontaktow
    public void czytajFile(){

	try{
		
     FileInputStream fis = new FileInputStream("conf/kontakty.txt");
	 BufferedReader br = new BufferedReader(new InputStreamReader(fis));
	 String line = null;
	 
	 

	 Vector tabl = new Vector();
	 
	 int i =1;
	 while ((line = br.readLine()) != null)
	        {
	          tabl.add(line);
	          i++;
	          lista.addElement(line);
	        }
	     fis.close();
	 }
        catch(IOException e){
        	JOptionPane.showMessageDialog(null,"Brak pliku z kontaktami");
        	
        }
}

//Formatka glowna
public void init(){
	

	//Sprawdzanie systemu operacyjnego
	OS=System.getProperty("os.name");
	System.out.println(OS);
	
	//Uruchomienia watku przesylania adresu
       nasloch N_s = new nasloch(); 
       
       	//Obluga TRAY-a
        SystemTray tray=null;
        try{
                tray = SystemTray.getSystemTray();
        }catch(Exception e){
                JOptionPane.showMessageDialog(null,"Prawdopodobnie masz starą wersję Javy, \n"+
        			"aplikacja wymaga java 1.6 (mustang)");
        			System.exit(-1);
        }
        ImageIcon image2 = new ImageIcon("icon/tray.png");
        Image image = (Image) image2.getImage();
        PopupMenu ppm = new PopupMenu();
        MenuItem hide = new MenuItem("Ukryj program");
        MenuItem show = new MenuItem("Pokaz program");
        MenuItem close = new MenuItem("Zamknij program");
        ppm.add(hide);
        ppm.add(show);
        //ppm.add(separator);
        ppm.add(close);
        hide.addActionListener(new ActionListener(){

 public void actionPerformed(ActionEvent ae){
	    frame.setVisible(false);
        	        }
 });
        
show.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
	     frame.setVisible(true);
        	        }
	});
	
	close.addActionListener(new ActionListener(){

 public void actionPerformed(ActionEvent ae){
	    System.exit(0);
        	        }
 });
        
       
TrayIcon trayIcon = new TrayIcon(image, "VKonf",ppm);
        try{
        	tray.add(trayIcon);
        }catch(AWTException e){
        	JOptionPane.showMessageDialog(null,"Prawdopodobnie masz starą wersję Javy, \n"+
        			"aplikacja wymaga java 1.6 (mustang)");
        }
	
	
	Container formatka = getContentPane();
	formatka.setLayout(new BorderLayout());



	//Dodawanie menu
	menuBar = new JMenuBar();
	JMenu fileMenu = new JMenu("Kontakty");         
	JMenu fileRoz = new JMenu("Konferencja");
	JMenu fileTool = new JMenu("Opcje");
	JMenu fileHelp = new JMenu("Pomoc");
    menuBar.add(fileMenu);
    menuBar.add(fileRoz);
    menuBar.add(fileTool);
    menuBar.add(fileHelp);
    rozItem = new JMenuItem("Nowa Rozmowa",new ImageIcon("icon/dzwonMini.png"));
	rozItem.setEnabled(false);
	
    JMenuItem newItem = new JMenuItem("Nowy Kontakt",new ImageIcon("icon/addUserMini.png"));
    JMenuItem delItem = new JMenuItem("Usun Kontakt",new ImageIcon("icon/removeUserMini.png"));
    JMenuItem formatItem = new JMenuItem("Wybor formatu",new ImageIcon("icon/check.png"));
    JMenuItem aReplyItem = new JMenuItem("Transmisja zwrotna", new ImageIcon("icon/check.png"));
    JMenuItem networkItem = new JMenuItem("Wybierz siec", new ImageIcon("icon/check.png"));
    JMenuItem pomocItem = new JMenuItem("Pomoc",new ImageIcon("icon/help.png"));
    JMenuItem aboutItem = new JMenuItem("O programie",new ImageIcon("icon/about.png"));
    JMenuItem onlineItem = new JMenuItem("Strona projektu",new ImageIcon("icon/browser.png"));
    final JMenuItem termItem = new JMenuItem("Terminal",new ImageIcon("icon/terminal.png"));
    termItem.setEnabled(false); 
    JMenuItem changeInPortItem = new JMenuItem("Porty odbioru", new ImageIcon("icon/check.png"));
    
     //podmenu
    fileMenu.add(newItem);
    fileRoz.add(rozItem);
    fileRoz.add(termItem);
    fileMenu.add(delItem);
    fileTool.add(networkItem);
    fileTool.add(formatItem);
    fileTool.add(aReplyItem);
    fileTool.add(changeInPortItem);
    fileHelp.add(pomocItem);
    fileHelp.add(aboutItem);
    fileHelp.add(onlineItem);
    formatka.add(menuBar);
    setJMenuBar(menuBar);


 //kacja dla O programie
    aboutItem.addActionListener(new ActionListener(){
    	public void actionPerformed(ActionEvent e){
    		System.out.println("O Programie ");
    		AboutProgram ap = new AboutProgram();
    		ap.setVisible(true);
    	}
    });



    //akcja dla pomocy
	pomocItem.addActionListener(new ActionListener(){
		
public void actionPerformed(ActionEvent e){
    HelpFrame help = new HelpFrame("conf/pomoc.html");
    help.setVisible(true);
    }
    });
         
  //akcja dla strona projektu
       
	onlineItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){
       if (Desktop.isDesktopSupported()){
          Desktop desktop = Desktop.getDesktop();
          URI uri = URI.create("www.programmers.wroclaw.pl");
          try{
          desktop.browse(uri);
          }catch(IOException ioe){
        	  JOptionPane.showMessageDialog(null,"Nie masz zdefiniowanej przeglądarki w środowisku X");
          }
       }
}
    });
   //zmienia porty na ktorych ma nasluchiwac aplikacja
	changeInPortItem.addActionListener(new ActionListener(){

		public void actionPerformed(ActionEvent e) {
			ChangePortFrame cPframe = new ChangePortFrame();
			cPframe.setVisible(true);
			
		}
		
	});
	
   //akcja dla wyboru sieci
	networkItem.addActionListener(new ActionListener(){
		
public void actionPerformed(ActionEvent e){
    LanOrWanFrame net = new LanOrWanFrame();
    net.setVisible(true);
    }
    });     
        
  //akcja dla wyboru formatu
        
	formatItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){
    FormatFrame FormatFrame = new FormatFrame();
    FormatFrame.setVisible(true);
          									}
        });
        
   //akcja dla wyboru auto reply
       aReplyItem.addActionListener(new ActionListener(){

 public void actionPerformed(ActionEvent e){
        AutoRepleyFrame aReplyFrame = new AutoRepleyFrame();
        aReplyFrame.setVisible(true);
          									}
        });
       
   
    //akcja terminal
    termItem.addActionListener(new ActionListener(){
 
public void actionPerformed(ActionEvent e){
		
	 Object[] values = wordList.getSelectedValues();
	    int ile = values.length;
	    adresy = new String[ile];

	    String IP = null;
		for (int i=0; i<=values.length-1; i++){
	    adresy[i] = values[i].toString();
	    IP=(adresy[i].substring(adresy[i].indexOf("*")+1,adresy[i].indexOf("/"))); 
	    }
     JFrame jf = new JFrame("terminal");
     Terminal terminal = new Terminal(IP);
     jf.add(terminal);
     jf.setSize(420,400);
     jf.setResizable(false);
     jf.setVisible(true);
 
     try {
   		Socket s = new Socket(IP, 8177);
   		PrintWriter out = new PrintWriter(s.getOutputStream());
   		//Wyslanie adresu IP
   		System.out.println("Rozpoczyna transmisje tekstowa");
   		out.println("//Start_CHEAT%%#"+sam_adres);
   		out.flush();
   		}
   		catch(IOException eppp)
   		{}	 
     
}
    }
   );    
       

  //akcja nowa rozmowa
   rozItem.addActionListener(new ActionListener(){
	   
public void actionPerformed(ActionEvent e){
        	
            try {
				newTalk(adresy,false);
			} catch (InvalidSessionAddressException e1) {
				e1.printStackTrace();
			} catch (UnsupportedFormatException e1) {
				e1.printStackTrace();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
          }
        });

   //Dodawanie kontaktu
    newItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)
			{addContact(); }
        												}
);

   //usuwanie kontaktu
	delItem.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e)
			{removContact();}
});


	JButton gAddButton = new JButton(new ImageIcon("icon/addUser.png"));
	gAddButton.setToolTipText("Dodaje kontakt");
	JButton gRemowButton = new JButton(new ImageIcon("icon/removeUser.png"));
	gRemowButton.setToolTipText("Usuwa Kontakt");
	gNewRozButton = new JButton(new ImageIcon("icon/dzwon.png"));
	gNewRozButton.setToolTipText("Zaczyna nowa konferencje");
	gNewRozButton.setEnabled(false);
	gCloseAllButton = new JButton(new ImageIcon("icon/stop.png"));
	gCloseAllButton.setToolTipText("Zamyka wszystkie aktywne rozmowy");
	JPanel gorny = new JPanel();
	gorny.add(gAddButton);
	gorny.add(gRemowButton);
	gorny.add(gNewRozButton);
	gorny.add(gCloseAllButton);
	gorny.setLayout(new GridLayout(1, 4));
	formatka.add(gorny, BorderLayout.NORTH);
	
	gCloseAllButton.addActionListener(new ActionListener(){
		public void actionPerformed(ActionEvent e){
			AV_Transmiting.stopTRANSMISION();
			System.out.println("STop Transmisji");
		}
	}
	);
	
	gAddButton.addActionListener(new ActionListener(){
    	   
public void actionPerformed(ActionEvent e)
                   {addContact();}
                										}
     );
        
    gRemowButton.addActionListener(new ActionListener(){
    	        
public void actionPerformed(ActionEvent e)
			{removContact();}
                }
      );
    
    
    
    
    
     gNewRozButton.addActionListener(new ActionListener(){
    	 
public void actionPerformed(ActionEvent e){
    	     
             try {
			newTalk(adresy,false);
			} catch (InvalidSessionAddressException e1) {
			e1.printStackTrace();
			} catch (UnsupportedFormatException e1) {
			e1.printStackTrace();
			} catch (IOException e1) {
			e1.printStackTrace();
						}
    	         						}
                										}	
     );
      

	 //tworzenie listy
	 lista = new DefaultListModel();
	 wordList = new JList(lista);
	 Font displayFont = new Font("Impact", Font.BOLD, 14);
	 wordList.setFont(displayFont);
	 wordList.setForeground(Color.white);
	 wordList.setBackground(Color.lightGray);
	 scrollPane = new JScrollPane(wordList);
	 formatka.add(scrollPane, BorderLayout.CENTER);

	 
	 //obsluga podwojnego klikniecia na liste
	 wordList.addMouseListener(new MouseAdapter(){
               
public void mouseClicked(MouseEvent evt) {
        if (evt.getClickCount() == 2) {
        Object[] selection = wordList.getSelectedValues();
        for (int i = 0; i < selection.length; i++) {
        word = (String) selection[i];

       String ping_ip_k=text.substring(word.indexOf("*")+2,word.indexOf("/")+1);
       ping k_ping = new ping(ping_ip_k);
        
        }
                        				}
                							} }
	 );
        
        
     //wywolanie metody zczytania z pliku listy kontaktow
      czytajFile();



	 //Obsluga podswietlenia listy
	   wordList.addListSelectionListener(new ListSelectionListener() {

 public void valueChanged(ListSelectionEvent event) {
	 	
	 	termItem.setEnabled(true);	 
        rozItem.setEnabled(true);
    	gNewRozButton.setEnabled(true);
        Object[] values = wordList.getSelectedValues();
        text = new StringBuffer(prefix);
        for (int i = 0; i < values.length; i++) {
        String word = (String) values[i];
        text.append(word);
        ping_ip=text.substring(text.indexOf("*")+1,text.indexOf("/"));
        nick=text.substring(1,text.indexOf("*"));
        label.setText(nick + " jest : " + "NIEDOSTEPNY");
        label.setAlignmentX(CENTER_ALIGNMENT);
        gNewRozButton.setEnabled(false);
        ping p = new ping(ping_ip);
              									}
              										}

        															}
	   );

	 //Etykieta
	 prefix=" ";
	 label = new JLabel(prefix);
	 dolny = new JPanel();
	 dolny.setLayout(new BoxLayout(dolny,BoxLayout.PAGE_AXIS));
	 dolny.add(label);



	 newContentPane = new CustomComboBoxDemo();
         dolny.add(newContentPane);
         formatka.add(dolny,BorderLayout.SOUTH);

	 //Seerver RTP
	rtp_serv rs = new rtp_serv();
      

	wlasciwosci = PropertyLoader.load("conf/System.properties");
	
	
		
	try{
	if (wlasciwosci.getProperty("NETWORK").contains("LAN")){
	
	try {
		caly_adres=(InetAddress.getLocalHost().toString());
		sam_adres=caly_adres.substring(caly_adres.indexOf("/")+1,caly_adres.length());
		
		} catch (UnknownHostException e1) {
			e1.printStackTrace();
		}
	}else
	{

		sam_adres=wlasciwosci.getProperty("NETWORK");
		sam_adres=wlasciwosci.getProperty("NETWORK");
	
	}
	}
	catch (NullPointerException ioe){
		CreateSystemProperties();
                JOptionPane.showMessageDialog(null,"Brak pliku konfiguracyjnego - System.propertes,\n"+
                "Tworze plik System.properties \n"+
                "Uruchom program jeszcze raz");
                System.exit(-1);
	}
//		Lista aktywnych polaczen
		act_o_connection = new Vector();
	}

public static void main(String[] args) {
		
		JApplet applet = new Komunikator();
	        frame = new JFrame("VKonf Ver 3.0");
		
		frame.addWindowListener(new WindowAdapter(){
                  public void actionClosing(WindowEvent we){
                         frame.setVisible(false);
                  }
                  });
        frame.getContentPane().add(applet);
		frame.setSize(260,400);
		frame.setResizable(false);
		applet.init();
		applet.start();
		frame.setVisible(true);
		frame.setIconImage(new ImageIcon("icon/icon.png").getImage());
	}

}
